<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>

		<script src="js/mui.min.js"></script>
		<script src="js/mui.picker.min.js"></script>
		<script src="js/jquery-3.4.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/dayjs.min.js" type="text/javascript" charset="utf-8"></script>

		<!--App自定义的css-->
		<link rel="stylesheet" type="text/css" href="css/app.css" />
		<link rel="stylesheet" type="text/css" href="css/mui.picker.min.css" />
		<link href="css/mui.min.css" rel="stylesheet" />


		<script type="text/javascript" charset="utf-8">
			// mui.init();
		</script>


	</head>
	<body>
		<div class="mui-content">
			<div class="mui-content-padded" style="margin: 5px;">
				<form class="mui-input-group" id="form_data" name="form_data">
					<div class="mui-input-row">
						<label>关键字</label>
						<input type="text" id="keyword" name="keyword" class="mui-input-clear" placeholder="关键字">
					</div>
					<div class="mui-input-row">
						<label>1.排他搜索</label>
						<input type="text" id="exclusive_search" name="exclusive_search" class="mui-input-clear"
							placeholder="排他信息">
					</div>
					<div class="mui-input-row">
						<label>2.精确搜索</label>
						<input type="text" id="refine_search" name="refine_search" class="mui-input-clear"
							placeholder="精确搜索信息">
					</div>
					<div class="mui-input-row">
						<label>3.站内搜索</label>
						<input type="text" id="site_search" name="site_search" class="mui-input-clear"
							placeholder="例如:csdn.com">
					</div>
					<div class="mui-input-row">
						<label>4.文件类型</label>
						<!-- <input type="text" id="site_search" name="site_search" class="mui-input-clear" placeholder="请输入关键字"> -->
						<select id="filetype" name="filetype" >
							<option value=""></option>

							<option value="pdf">pdf</option>
							<option value="ppt">ppt</option>
							<!-- <option value="pptx">pptx</option> -->
							<option value="doc">doc</option>
							<!-- <option value="docx">docx</option> -->
							<option value="xls">xls</option>
							<!-- <option value="xlsx">xlsx</option> -->

							<option value="zip">zip</option>
							<option value="exe">exe</option>
							<option value="dmg">dmg</option>

							<option value="txt">txt</option>
							<option value="mobi">mobi</option>
							<option value="epub">epub</option>
							<option value="azw3">azw3</option>

							<option value="mp3">mp3</option>
							<option value="wma">wma</option>
							<option value="midi">midi</option>
							<option value="flac">flac</option>
							<option value="ape">ape</option>
							<option value="aac">aac</option>
							<option value="wav">wav</option>

							<option value="mp4">mp4</option>
							<option value="avi">avi</option>
							<option value="rmvb">rmvb</option>
							<option value="flv">flv</option>
							<option value="mkv">mkv</option>
							<option value="3gp">3gp</option>

							<option value="jpg">jpg</option>
							<option value="png">png</option>
							<option value="gif">gif</option>
						</select>
						<!-- <button id='showUserPicker' class="mui-btn mui-btn-block" type='button'>一级选择示例 ...</button> -->
					</div>
					<div class="mui-input-row">
						<label>5.标题搜索</label>
						<input type="text" id="title" name="title" class="mui-input-clear" placeholder="搜索结果要包含的 标题">
					</div>
					<div class="mui-input-row">
						<label>6.正文搜索</label>
						<input type="text" id="text_search" name="text_search" class="mui-input-clear"
							placeholder="搜索结果要包含的 正文">
					</div>
					<div class="mui-input-row">
						<label>7.正文全配</label>
						<input type="text" id="alltext_search" name="alltext_search" class="mui-input-clear"
							placeholder="多个用空格隔开">
					</div>
					<div class="mui-input-row">
						<label>8.url搜索</label>
						<input type="text" id="url_search" name="url_search" class="mui-input-clear"
							placeholder="例如:cnki.net">
					</div>
					<div class="mui-input-row">
						<label>9.时间限制</label>
						<!-- <input type="text" id="site_search" name="site_search" class="mui-input-clear" placeholder="请输入关键字"> -->
						<select id="time_limit_within_type" name="time_limit_within_type">
							<option value=""></option>
							<option value="within_day">一天内</option>
							<option value="within_week">一周内</option>
							<option value="within_month">一月内</option>
							<option value="within_year">一年内</option>
						</select>
					</div>
					<div class="mui-input-row">
						<label>开始日期</label>
						<!-- <input type="text" id="input_startDate" name="input_startDate" class="mui-input-clear" placeholder="开始时间"> -->
						<!-- <input type="text" id="input_endDate" name="input_endDate" class="mui-input-clear" placeholder="结束时间"> -->
						<!-- 	<button id='input_startDate' data-options='{"type":"date","beginYear":1970,"endYear":2050}' class="btn mui-btn mui-btn-block">选择日期</button>
						<button id='input_endDate' data-options='{"type":"date","beginYear":1970,"endYear":2050}' class="btn mui-btn mui-btn-block">选择日期</button>
					 -->
						<input type="text" style="width: 150px;" id="input_startDate" name="input_startDate"
							placeholder="开始时间" />

						<button type="button" style="float: left;" onclick="select_start_date()">选择</button>

					</div>

					<div class="mui-input-row">
						<label>结束日期</label>
						<input type="text" style="width: 150px;" id="input_endDate" name="input_endDate"
							placeholder="结束时间" />

						<button type="button" style="float: left;" onclick="select_end_date()">选择</button>


					</div>
					<div class="mui-input-row">
						<label>搜索引擎</label>
						<select id="searchtype" name="searchtype">
							<option value=""></option>
							<option value="baidu">baidu.com</option>
							<option value="bing">bing.com</option>
							<option value="google">google.com</option>
						</select>
					</div>

					<div class="mui-button-row">
						<button type="button" class="mui-btn mui-btn-primary"
							onclick="ajax_submit()">搜索</button>&nbsp;&nbsp;
						<button type="reset" class="mui-btn mui-btn-danger" >重置</button>
						<a href="tips.html"  class="mui-btn mui-btn">使用帮助</a>
						<a href="pc.html"  class="mui-btn mui-btn-success">切换电脑版</a>
					</div>
				</form>
			</div>
		</div>

		<script type="text/javascript">
			// var input_startDate = $('#input_startDate');
			// var input_endDate = $('#input_endDate');

			// var input_startDate='";
			// 	var input_endDate='";

			function select_start_date() {
				// alert("666");

				var dtpicker = new mui.DtPicker({
					"type": "date"
				})
				dtpicker.show(function(e) {
					// console.log(e); 
					// $("#input_startDate").val("2021-12-21");
					$("#input_startDate").val(e.text);
				})

			}

			function select_end_date() {
				// alert("666");
				var dtpicker = new mui.DtPicker({
					"type": "date"
				})
				dtpicker.show(function(e) {
					// console.log(e); 
					// $("#input_startDate").val("2021-12-21");
					$("#input_endDate").val(e.text);
				})
			}



			function ajax_submit() {
				// alert("666");
				// var form_data=$('#form_data').serialize();
				// alert("form_data:"+form_data);

				var today_YMD_0 = dayjs().format("YYYY-MM-DD");
				// alert("today_YMD_0"+today_YMD_0);

				// 搜索的文件类型的下拉列表
				var filetype_obj = $("#filetype option:selected");
				var filetype = filetype_obj.val();

				// 搜索引擎的下拉列表
				var searchtype_obj = $("#searchtype option:selected");
				var searchtype = searchtype_obj.val();

				// 时间限制的下拉列表
				var time_limit_within_type_obj = $("#time_limit_within_type option:selected");
				var time_limit_within_type = time_limit_within_type_obj.val();

				// 追加在搜索引擎后面的文本
				var search_text = "";
				// +" ";




				var keyword = $("#keyword").val();
				// alert("keyword:" + keyword);
				if (!is_empty(keyword)) {
					// search_text.concat(keyword);
					search_text = search_text + keyword + " ";
				}





				// 2精确
				var refine_search = $("#refine_search").val();
				// alert("refine_search:" + refine_search);
				if (!is_empty(refine_search)) {
					// search_text.concat(keyword);
					search_text = search_text + "\"" + refine_search + "\"" + " ";
				}

				// 排他搜索要放到精确搜索之后,否则搜索出的内容不符合预期
				var exclusive_search = $("#exclusive_search").val();
				// alert("exclusive_search:" + exclusive_search);
				if (!is_empty(exclusive_search)) {
					// search_text.concat(keyword);
					search_text = search_text + " -" + exclusive_search + " ";
				}

				var site_search = $("#site_search").val();
				// alert("site_search:" + site_search);
				if (!is_empty(site_search)) {
					// search_text.concat(keyword);
					search_text = search_text + " site:" + site_search + " ";
				}

				// var filetype = $("#filetype").val();
				// alert("filetype:" + filetype);
				if (!is_empty(filetype)) {
					// search_text.concat(keyword);
					search_text = search_text + " filetype:" + filetype + " ";
				}

				var title = $("#title").val();
				// alert("title:" + title);
				if (!is_empty(title)) {
					// search_text.concat(keyword);
					search_text = search_text + " intitle:" + title + " ";
				}

				var text_search = $("#text_search").val();
				// alert("text_search:" + text_search);
				if (!is_empty(text_search)) {
					// search_text.concat(keyword);
					search_text = search_text + " intext:" + text_search + " ";
				}

				var alltext_search = $("#alltext_search").val();
				// alert("alltext_search:" + alltext_search);
				if (!is_empty(alltext_search)) {
					// search_text.concat(keyword);
					search_text = search_text + " allintext:" + alltext_search + " ";
				}

				var url_search = $("#url_search").val();
				// alert("url_search:" + url_search);
				if (!is_empty(url_search)) {
					// search_text.concat(keyword);
					search_text = search_text + " url:" + url_search + " ";
				}

				// 百度的搜索的时间限制规则:年月日转为秒为单位的时间戳。开始时间和结束时间都是用时间戳

				// 微软bing的搜索的时间限制规则:
				// 格林时间1970-01-01为第0天
				// 第18788天为2021-06-10。搜索0~18788天是1970-01-01到2021-06-10



				var start_time_baidu = "";
				var end_time_baidu = "";
				var limit_time_scope = "";

				var start_time_bing = "";
				var end_time_bing = "";
				var limit_time_scope_bing = "";


				// 格林时间 1970-01-01开始时间。因为互联网都默认这个是开始时间
				// 时间戳
				// 毫秒（-28800000）
				const GT_1970_01_01_millisecond = dayjs('1970-01-01');
				// 秒为单位(保留两位小数点)
				const GT_1970_01_01_second = GT_1970_01_01_millisecond / 1000;
				// 秒为单位(只保留整数位)
				const GT_1970_01_01_second_int = parseInt(GT_1970_01_01_second);

				// 当前时间
				const GT_nowDay_millisecond = dayjs();
				const GT_nowDay_second = GT_nowDay_millisecond / 1000;
				const GT_nowDay_second_int = parseInt(GT_nowDay_second);



				// var input_startDate="2021-06-01";
				// var input_endDate="2021-06-10";

				var input_startDate = $("#input_startDate").val();
				var input_endDate = $("#input_endDate").val();

				// alert("input_startDate:"+input_startDate);
				// alert("input_endDate:"+input_endDate);

				// 当前时间 dayjs().format()
				var today_YMD = dayjs().format("YYYY-MM-DD");
				const default_startTime = dayjs('2000-01-01');

				// laydate选中后，默认是强制填充日期的。判定再填充开始时间和结束时间，是怕哪个萌新把日期用删除键（Backspace、delete）删除了
				if (is_empty(time_limit_within_type)) {
					// 没开始时间，有结束时间
					if ((is_empty(input_startDate)) && (!is_empty(input_endDate))) {
						input_startDate = default_startTime;
						// alert("input_startDate is null");
					}
					// 有开始时间，没结束时间
					if ((!is_empty(input_startDate)) && (is_empty(input_endDate))) {
						input_endDate = today_YMD;
						// alert("input_endDate is null");
					}
				}



				const input_startDate_millisecond = dayjs(input_startDate);
				const input_startDate_second = input_startDate_millisecond / 1000;
				const input_startDate_second_int = parseInt(input_startDate_second);

				const input_endDate_millisecond = dayjs(input_endDate);
				const input_endDate_second = input_endDate_millisecond / 1000;
				const input_endDate_second_int = parseInt(input_endDate_second);






				// 一天内(昨天这个时候的毫秒)
				// 返回毫秒
				var yesterday_millisecond = dayjs().subtract(1, 'day');
				const yesterday_second = yesterday_millisecond / 1000;
				const yesterday_second_int = parseInt(yesterday_second);

				// alert("print:"+yesterday_second_int);

				// 一周内（上周这个时候的毫秒）
				var last_week_millisecond = dayjs().subtract(1, 'week');
				const last_week_second = last_week_millisecond / 1000;
				const last_week_second_int = parseInt(last_week_second);

				// 一个月内（上个月这个时候的毫秒）
				var last_month_millisecond = dayjs().subtract(1, 'month');
				const last_month_second = last_month_millisecond / 1000;
				const last_month_second_int = parseInt(last_month_second);

				// 一年内（去年这个时候的毫秒）
				var yester_year_millisecond = dayjs().subtract(1, 'year');
				const yester_year_second = yester_year_millisecond / 1000;
				const yester_year_second_int = parseInt(yester_year_second);

				// 微软
				const gt_to_nowDay = my_betweenDay(GT_1970_01_01_millisecond, GT_nowDay_millisecond);
				const gt_to_yesterday = my_betweenDay(GT_1970_01_01_millisecond, yesterday_millisecond);
				const gt_to_last_week = my_betweenDay(GT_1970_01_01_millisecond, last_week_millisecond);
				const gt_to_last_month = my_betweenDay(GT_1970_01_01_millisecond, last_month_millisecond);
				const gt_to_last_year = my_betweenDay(GT_1970_01_01_millisecond, yester_year_millisecond);

				const gt_to_input_startDate = my_betweenDay(GT_1970_01_01_millisecond, input_startDate_millisecond);
				const gt_to_input_endDate = my_betweenDay(GT_1970_01_01_millisecond, input_endDate_millisecond);




				// 一天内
				if (time_limit_within_type == "within_day") {


					start_time_baidu = yesterday_second_int;
					end_time_baidu = GT_nowDay_second_int;
					limit_time_scope = "&gpc=stf=" + start_time_baidu + "," + end_time_baidu + "|stftype=2&tfflag=1";

					// start_time_bing = gt_to_yesterday;
					// end_time_bing = gt_to_nowDay;
					// limit_time_scope_bing = "&filters=ex1%3a%22ez5_" + start_time_bing + "_" + end_time_bing +
					// 	"%22&go=%e6%90%9c%e7%b4%a2&qs=ds";

					limit_time_scope_bing = "&filters=ex1%3a%22ez1%22&go=%e6%90%9c%e7%b4%a2&qs=ds";

				}
				//一周内
				if (time_limit_within_type == "within_week") {
					start_time_baidu = last_week_second_int;
					end_time_baidu = GT_nowDay_second_int;
					limit_time_scope = "&gpc=stf=" + start_time_baidu + "," + end_time_baidu + "|stftype=2&tfflag=1";

					// start_time_bing = gt_to_last_week;
					// end_time_bing = gt_to_nowDay;
					// limit_time_scope_bing = "&filters=ex1%3a%22ez5_" + start_time_bing + "_" + end_time_bing +
					// 	"%22&go=%e6%90%9c%e7%b4%a2&qs=ds";
					limit_time_scope_bing = "&filters=ex1%3a%22ez2%22&go=%e6%90%9c%e7%b4%a2&qs=ds";
				}
				// 一月内
				if (time_limit_within_type == "within_month") {
					start_time_baidu = last_month_second_int;
					end_time_baidu = GT_nowDay_second_int;
					limit_time_scope = "&gpc=stf=" + start_time_baidu + "," + end_time_baidu + "|stftype=2&tfflag=1";

					// start_time_bing = gt_to_last_month;
					// end_time_bing = gt_to_nowDay;
					// limit_time_scope_bing = "&filters=ex1%3a%22ez5_" + start_time_bing + "_" + end_time_bing +
					// 	"%22&go=%e6%90%9c%e7%b4%a2&qs=ds";

					limit_time_scope_bing = "&filters=ex1%3a%22ez3%22&go=%e6%90%9c%e7%b4%a2&qs=ds";

				}
				// 一年内
				if (time_limit_within_type == "within_year") {
					start_time_baidu = yester_year_second_int;
					end_time_baidu = GT_nowDay_second_int;
					limit_time_scope = "&gpc=stf=" + start_time_baidu + "," + end_time_baidu + "|stftype=2&tfflag=1";

					start_time_bing = gt_to_last_year;
					end_time_bing = gt_to_nowDay;
					limit_time_scope_bing = "&filters=ex1%3a%22ez5_" + start_time_bing + "_" + end_time_bing +
						"%22&go=%e6%90%9c%e7%b4%a2&qs=ds";

				}



				// 手动输入时间
				if ((!is_empty(input_startDate)) || (!is_empty(input_endDate))) {
					limit_time_scope = "";
					limit_time_scope_bing = "";

					start_time_baidu = input_startDate_second_int;
					end_time_baidu = input_endDate_second_int;

					start_time_bing = gt_to_input_startDate;
					end_time_bing = gt_to_input_endDate;

					limit_time_scope = "&gpc=stf=" + start_time_baidu + "," + end_time_baidu + "|stftype=2&tfflag=1";
					limit_time_scope_bing = "&filters=ex1%3a%22ez5_" + start_time_bing + "_" + end_time_bing +
						"%22&go=%e6%90%9c%e7%b4%a2&qs=ds";
				}



				if (searchtype == "baidu") {
					window.open("https://m.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&ch=&tn=baidu&bar=&wd=" + search_text +
						limit_time_scope);
				} else if (searchtype == "bing") {
					window.open("https://cn.bing.com/search?q=" + search_text + limit_time_scope_bing);
				} else if (searchtype == "google") {
					window.open("https://www.google.com/search?q=" + search_text);
				}

				// 未选中,默认选择百度
				if (is_empty(searchtype)) {
					window.open("https://m.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&ch=&tn=baidu&bar=&wd=" + search_text +
						limit_time_scope);
				}



			}


			// 判空
			function is_empty(my_val) {
				if (my_val == null || my_val == undefined || my_val == "") {
					return true;
				} else {
					return false;
				}
				// alert("is_empty:");
			}


			// 返回 相差多少天，入参是毫秒
			function my_betweenDay(start, end) {
				return end.diff(start, 'day');
			}


			function test_value() {
				// var obj = $("#filetype option:selected");
				// var artime_val = obj.val();
				// var artime_text = obj.text();
				// alert("artime_val:" + artime_val);
				// alert("artime_text:" + artime_text);
				// data_output
			}
		</script>
	</body>
</html>
